<template>
	<view class="withdrawal">
		<view class="withdrawal_content">
			<view class="withdrawal_content_info flex">
				<view class="left">
					<image :src="util.imageApi+GoodsDetail.image" mode=""></image>
				</view>
				<view class="center">
					<view class="center_title">
						{{GoodsDetail.storeName}}
					</view>
					<view class="center_item">
						<label>￥</label>{{GoodsDetail.price}}元
					</view>
				</view>
				<view class="right">
					数量：
					<span class="border_left" @click="handleDeleteSum">-</span>
					<span class="border_center">{{sum}}</span>
					<span class="border_right" @click="handleAddSum">+</span>
				</view>
				<view class="yue">余额：{{pointsDynamic}}</view>
			</view>
		</view>
		<view class="withdrawal_content">
			<view class="withdrawal_content_info">
				<view class="item">
					<label>鸡蛋价格：</label>2元/枚
				</view>
				<view class="item">
					<label>付款金额：</label>{{GoodsDetail.price*sum}}
				</view>
			</view>
		</view>
		<view class="withdrawal_content">
			<view class="withdrawal_content_title">
				收款信息
			</view>
			<view class="withdrawal_content_info">
				<view class="item">
					<label>银行卡号：</label>{{detail.bankAccount}}
				</view>
				<view class="item">
					<label>收款人：</label>{{detail.accountRealname}}
				</view>
				<view class="item">
					<label>开户行：</label>{{detail.bankName}}
				</view>
				<view class="item">
					<label>所属银行：</label>{{detail.subbranch}}
				</view>
				<view class="item">
					<label>地区：</label>{{detail.localtion}}
				</view>
				<view class="item">
					<label>手机号：</label>{{detail.bankPhone}}
				</view>
				<view class="item">
					<label>身份证号：</label>{{detail.mySelf}}
				</view>
			</view>
			<span class="span" @click="handleClick">选择收款信息</span>
		</view>
		<view class="address_btn" v-if="numb">
			<button type="primary" @click="handleSubmit">提交</button>
		</view>
		<view class="address_btn" v-else>
			<button type="primary">不可提现</button>
		</view>

		<paypass ref="yspay" @cancel="handleClose" @submit="submitpay"></paypass>
	</view>
</template>

<script>
	import paypass from "@/components/ys-paypass/ys-paypass.vue";
	import util from "@/util/index.js"
	export default {
		components: {
			paypass
		},
		data() {
			return {
				serviceCharge: 0,
				util: util,
				address: {},
				sum: 1,
				priceScore: 0,
				detail: {},
				GoodsDetail: {},
				pointsDynamic: '',
				pricep: 0,
				ID: '',
				numb: true,
			}
		},
		onShow() {
			// 查询账户银行信息
			this.$http({
				url: '/memberBank/getMemberBank',
				method: 'GET'
			}).then(res => {
				if (res.data.code === 200 && res.data.data) {
					this.detail = res.data.data
				}
			})

		},
		onLoad(e) {
			this.$http({
				url: '/receiveEggsInfo'
			}).then(res => {
				this.GoodsDetail = res.data.data
				this.pricep = res.data.data.price
			})
			this.$http({
				url: "/member/getMyPage"
			}).then(res => {
				this.pointsDynamic = res.data.data.pointsDynamic
				this.ID = res.data.data.memberId
				if (res.data.data.chickenNum < 20) {
					this.numb = false
				}
			})
		},
		methods: {
			handleClose() {

			},
			submitpay(ex) {
				let arr = {
					orderSrc: '3', // 订单来源
					amount: 100 * this.sum, // 实际支付金额
					deliverMoney: 0, // 运费
					// harvestAddressId:this.address.id,// 收货地址ID
					totalAmount: 190 * this.sum, // 订单总金额
					num: this.sum,
					id: this.GoodsDetail.id, // 商品ID
					orderType: "3", // 订单类型
					deliveryStatus: "1", // 提货方式
					processingFee: this.serviceCharge,
					payType: 2, //支付鸡蛋
					payPass: ex.value, //支付密码
					memberId: this.ID, //用户id
				}
				this.$http({
					url: '/payEggs',
					data: arr
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '支付成功',
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
						this.handleClose()
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'error'
						}).then(this.Passshow = true)
					}
				})
			},
			handleSubmit() {
				if (!this.detail.id) {
					uni.showToast({
						title: "请先填写收款人信息",
						icon: 'error'
					})
					return
				}
				if (!this.detail.mySelf || !this.detail.accountRealname || !this.detail.bankAccount || !this.detail
					.bankName || !this.detail.bankPhone || !this.detail.localtion || !this.detail.subbranch) {
					uni.showToast({
						title: "请完整填写身份信息",
						icon: 'error'
					})
					return
				}
				if (this.pricep * this.sum > this.pointsDynamic) {
					uni.showToast({
						title: "余额不足",
						icon: 'error'
					})
					return
				}
				this.$refs.yspay.show();

			},
			handleClick() {
				uni.navigateTo({
					url: '/pages/payeeInfo/payeeInfo'
				})
			},
			handleAddSum() {
				this.sum++
			},
			handleDeleteSum() {
				if (this.sum !== 0) {
					this.sum--
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	@import './withdrawal.css'
</style>
